-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Gesture relations #3693
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
m-bert
wants to merge
55
commits into
next
Choose a base branch
from
@mbert/relations-v2
base: next
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Gesture relations #3693
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
m-bert
commented
Sep 5, 2025
export type ComposedGestureType = ValueOf<typeof ComposedGestureType>; | ||
|
||
// TODO: Find better name | ||
export const HandlerType = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure about this name so if you have any idea how to name it let me know 😅
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Important
Supersede #3664.
I've decided to create a separate PR since it was easier to start working on it directly than waiting for #3682 to be merged.
Description
This PR introduces hooks to set relations between handlers.
API
New API replaces the old one as follows:
Gesture.Race(g1, g2)
useRace(g1, g2)
Gesture.Exclusive(g1, g2)
useExclusive(g1, g2)
Gesture.Simultaneous(g1, g2)
useSimultaneous(g1, g2)
Algorithm for populating relations
Handling external relations
In order to properly handle gesture relations, we need to pass 3 arrays to the native side:
waitFor
- responsible for handlingExclusive
andrequireExternalGestureToFail
relationssimultaneousHandlers
- responsible forSimultaneous
andsimultaneousWithExternalGesture
relationsblocksHandlers
- responsible forblocksExternalGesture
relationAt first, these arrays are filled with external relations in
useGesture
hook. Then we useDFS
algorithm to add remaining relations, added with relation hooks. SinceRace
doesn't really change anything when it comes to gesture interactions, we can ignore it in our algorithm.DFS overview
We use
DFS
because gesture relations form tree structure.The algorithm works as follows:
waitFor
andsimultaneousHandlers
. If root node isSimultaneousGesture
, we also add its handler tags intosimultaneousHandlers
array. This ensures that the algorithm works even if we have onlySimultaneous
as the root node (e.g.useSimultaneous(g1, g1)
)ComposedGesture
, it means that we reached leaf node. In that case we populatewaitFor
andsimultanoursHandlers
arrays intonode
arrays and then update relations on the native sideComposedGesture
, then for each child:ComposedGesture
:traverseGestureRelations
to reach stop condition and configure relations on the native sideExclusive
, then we add childtag
towaitFor
arrayComposedGesture
:non-simultaneous
gesture tosimultaneous
gesture we add all child tags into globalsimulatneousHandlers
arraysimultaneous
tonon-simultaneous
gesture, we remove child tags instead of adding.waitFor
to reset it later.traverseGestureRelations
simultaneous
(child) tonon-simultaneous
(node) gesture, we remove node tags fromsimultaneousHandlers
non-simultaneous
(child) tosimultaneous
(node) gesture we add node tags instead of removingExclusive
gesture means that we want to add all children tags intowaitFor
Exclusive
child tonon-exclusive
node, we want to resetwaitFor
to previous state, usinglength
variable.Example
Below you can see example of the algorithm.
We use the following notation:
E
-Exclusive
S
-Simultaneous
P
-Pan
T
-Tap
SH
-simultaneousHandlers
WF
-waitFor
+=
- adding tags-=
- removing tagsNote: vertex label in relation arrays expands to all tags in the composed gesture.
Limitations
Currently the following setup doesn't work on
android
:I've managed to find out what is the difference between this and using only
useRace
.Warning
This problem seems to be present also on
main
, so I think it will be better to solve it in the follow-up PR.For now, external relation props do not support composed gestures. Let me know if this should be done in this PR, or in a follow-up.
Test plan
Same detector interactions
Verified that the following relations work:
Android
Simultaneous
Exclusive
Race
Exclusive
+Simultaneous
iOS
Simultaneous
Exclusive
Race
Exclusive
+Simultaneous
Base code used for testing:
Cross detector interactions
Verified that the following relations work:
Android
simultaneousWithExternalGesture
requireExternalGestureToFail
blocksExternalGesture
iOS
simultaneousWithExternalGesture
requireExternalGestureToFail
blocksExternalGesture
Base code used for testing: